# 对比实验脚本：比较MCTS和进化算法性能
# 用法: .\tools\run_comparison_experiment.ps1 -Tasks 0,1,2,3,4,5,6,7,8,9

param(
    [Parameter(Mandatory=$false)]
    [int[]]$Tasks = (0..9),  # 默认运行前10个任务

    [Parameter(Mandatory=$false)]
    [string]$MctsConfig = "config/qwen32b_bird_dev.yaml",

    [Parameter(Mandatory=$false)]
    [string]$EvolutionaryConfig = "config/qwen32b_bird_dev_evolutionary.yaml",

    [Parameter(Mandatory=$false)]
    [int]$Rollouts = 4,

    [Parameter(Mandatory=$false)]
    [string]$OutputPrefix = "comparison_experiment_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
)

Write-Host "=== Alpha-SQL 对比实验 ===" -ForegroundColor Green
Write-Host "MCTS配置: $MctsConfig" -ForegroundColor Yellow
Write-Host "进化算法配置: $EvolutionaryConfig" -ForegroundColor Yellow
Write-Host "任务ID: $($Tasks -join ', ')" -ForegroundColor Yellow
Write-Host "MCTS轮次: $Rollouts" -ForegroundColor Yellow
Write-Host "输出前缀: $OutputPrefix" -ForegroundColor Yellow
Write-Host ("-" * 50) -ForegroundColor Cyan

# 设置环境变量
$env:OPENAI_API_KEY = 'deepseek-chat'

# 运行对比实验
$taskList = $Tasks -join ","
$cmd = "python tools/run_comparison_experiment.py --tasks $taskList --mcts-config $MctsConfig --evolutionary-config $EvolutionaryConfig --rollouts $Rollouts --output-prefix $OutputPrefix"

Write-Host "执行命令: $cmd" -ForegroundColor Gray

try {
    & cmd /c $cmd
    if ($LASTEXITCODE -eq 0) {
        Write-Host "`n实验完成！结果已保存。" -ForegroundColor Green
    } else {
        Write-Host "`n实验失败，退出代码: $LASTEXITCODE" -ForegroundColor Red
    }
} catch {
    Write-Host "执行出错: $($_.Exception.Message)" -ForegroundColor Red
}